package com.bjpowernode.springboot.controller;

import com.bjpowernode.springboot.entity.Student;
import com.bjpowernode.springboot.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;


    @RequestMapping("/selectById")
    @ResponseBody
    public Student queryStudentById(int id) {
        return studentService.queryStudentById(id);
    }

    @RequestMapping("/updateById")
    @ResponseBody
    public String updateStudentById(int id, String newName) {
        /*将更新之后的内容封装到student对象中*/
        Student student = new Student();
        student.setId(id);
        student.setName(newName);
        int queryCount = studentService.updateStudentById(student);
        if (queryCount > 0) return "编号:"+id+"的学生姓名成功修改为:"+newName;
        return "编号:"+id+"的学生姓名修改失败";
    }

    @RequestMapping("/test")
    @ResponseBody
    public String connect() {
        return "connect success 010";
    }


}
